package cloud.quan.controller;

import cloud.common.util.Result;
import cloud.quan.service.impl.PddServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pdd")
@Api(tags = "拼多多")
public class PddController {
    @Autowired
    PddServiceImpl pddService;

    @GetMapping("/goodsDetail")
    @ApiOperation("商品详情")
    public Result goodsDetail(@RequestParam @ApiParam(value = "商品 id", example = "0", required = true) Long goodsId,
                              @RequestParam @ApiParam(value = "推广位 id", required = true) String pId) throws Exception {
        String goodsDetail = pddService.goodsDetail(goodsId, pId);
        return new Result().ok(goodsDetail);
    }

    @GetMapping("/goodsPage")
    @ApiOperation("商品分页")
    public Result page(@RequestParam(defaultValue = "1") @ApiParam(example = "1", type = "Integer") Integer page,
                       @RequestParam(defaultValue = "10") @ApiParam(example = "10", type = "Integer") Integer pageSize,
                       @RequestParam(defaultValue = "0") @ApiParam(value = "上一次查询结果 id", example = "0") String listId,
                       @RequestParam(defaultValue = "0") @ApiParam(value = "排序", example = "0", type = "Integer") Integer sortType,
                       @RequestParam(defaultValue = "8924949_103152019") @ApiParam(value = "推广位id", example = "8924949_103152019") String pId,
                       @RequestParam(required = false) @ApiParam(value = "关键字") String keyword)
            throws Exception {
        String goodsPage = pddService.goodsSearch(keyword, page, pageSize, sortType, pId, listId);
        return new Result().ok(goodsPage);
    }

    @GetMapping("/goodsOpt")
    @ApiOperation("商品标签")
    public Result goodsOpt(@RequestParam(defaultValue = "0") @ApiParam(example = "0", type = "Integer") Integer parentOptId) throws Exception {
        String goodsOpt = pddService.goodsOptGet(parentOptId);
        return new Result().ok(goodsOpt);
    }

    @GetMapping("/goodsCats")
    @ApiOperation("商品类目")
    public Result goodsCatsGet(@RequestParam(defaultValue = "0") @ApiParam(example = "0") Long parentCatId) throws Exception {
        String goodsCats = pddService.goodsCatsGet(parentCatId);
        return new Result().ok(goodsCats);
    }

    @GetMapping("/themeList")
    @ApiOperation("主题列表")
    public Result themeList(@RequestParam(defaultValue = "1") @ApiParam(example = "1", type = "Integer") Integer page,
                            @RequestParam(defaultValue = "5") @ApiParam(example = "5", type = "Integer") Integer pageSize) throws Exception {
        String themeList = pddService.themeListGet(pageSize, page);
        return new Result().ok(themeList);
    }

    @GetMapping("/themeGoods")
    @ApiOperation("主题商品")
    public Result themeGoodsSearch(@RequestParam @ApiParam(value = "主题 id", example = "0", required = true) Long themeId) throws Exception {
        String themeGoods = pddService.themeGoodsSearch(themeId);
        return new Result().ok(themeGoods);
    }

    @GetMapping("/goodsPromotionUrl")
    @ApiOperation("商品推广链接")
    public Result goodsPromotionUrlGenerate(@RequestParam @ApiParam(value = "推广位 id", required = true) String pId,
                                            @RequestParam @ApiParam(value = "商品 id", example = "0", required = true) Long goodsId,
                                            @RequestParam @ApiParam(value = "搜索 id", required = true) String searchId) throws Exception {
        String goodsPromotionUrl = pddService.goodsPromotionUrlGenerate(pId, goodsId, searchId);
        return new Result().ok(goodsPromotionUrl);
    }


}
